<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body onload="init()">
		学号：<input type="text" id="stuNO"/>
		<br>
		姓名：<input type="text" id="stuName"/>
		<button type="button" onclick="next()">下一个</button>
	</body>
	<script type="text/javascript">
		let stus=[];
		function init(){
			let xhr=new XMLHttpRequest();
			xhr.open("get","students.xml",false);
			xhr.send();
			let xml=xhr.responseXML;//以XML格式接受服务器数据
			stus= xml.querySelectorAll("students>student");
			console.log(stus)
			document.getElementById("stuNO").value=stus[0].getAttribute("sno");
			document.getElementById("stuName").value=stus[0].getAttribute("name");
		}
		let i=0;
		function next(){
			//越界处理
			i++; 
			if(i>=stus.length){
				i=0;
			}
			document.getElementById("stuNO").value=stus[i].getAttribute("sno");
			document.getElementById("stuName").value=stus[i].getAttribute("name");
		}
		
	</script>
</html>
